package com.qf.sy2103.ssm.interceptor;

import com.qf.sy2103.ssm.constants.Constants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Objects;

@Slf4j
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object userlogin = request.getSession().getAttribute("userlogin");
        if (Objects.nonNull(userlogin)){
            return true;
        }
        response.sendRedirect("/login.html");

        return false;
    }
}
